package vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;

import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import modelo.FraseDAO;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class prueba extends javax.swing.JFrame implements ActionListener {
	private JLabel lblPalabra;
	
	private Vector<FraseDAO> frases;
	
	FraseDAO fraseDAO;
	private JButton btnBuscar;
	private JTextField txtLetra;

	/**
	* Auto-generated main method to display this JFrame
	*/
	/*public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				prueba inst = new prueba();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}*/
	
	public prueba() {
		super();
		fraseDAO = new FraseDAO();
		fraseDAO.leerFrase(1);
		//frases = fraseDAO.obtenerFrase();
		
		//System.out.println("numero de palabras: "+frases.size());
		
		initGUI();		
		
		fraseDAO= frases.get(0);
		
		//actualizar(fraseDAO.separarFrase());
		
	}
	
	public void actualizar(String palabra){
    	this.lblPalabra.setText( palabra );
    }
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				lblPalabra = new JLabel();
				getContentPane().add(lblPalabra);
				lblPalabra.setText("MANOLO");
				lblPalabra.setBounds(12, 182, 554, 65);
				lblPalabra.setFont(new java.awt.Font("Segoe UI",1,26));
			}
			{
				txtLetra = new JTextField();
				getContentPane().add(txtLetra);
				txtLetra.setBounds(26, 76, 121, 23);
			}
			{
				btnBuscar = new JButton();
				getContentPane().add(btnBuscar);
				btnBuscar.setText("Buscar");
				btnBuscar.setBounds(173, 76, 90, 23);
				btnBuscar.setActionCommand("buscar");
				btnBuscar.addActionListener(this);
			}
			pack();
			this.setSize(592, 333);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public String getLetra(){
		return this.txtLetra.getText().toLowerCase();
	}
	
	public void actionPerformed(ActionEvent e) {
		if ( "buscar".equals(e.getActionCommand()) ) {
      		/*Buscamos si existe la letra en palabra.*/
      		//if( fraseDAO.buscarLetra(getLetra()) ){
      			//System.out.println("x teclado: "+getLetra());
      			//System.out.println("x BD: "+fraseDAO);
      			//fraseDAO.revelarFrase();
      			//actualizar( fraseDAO.separarFrase() );
      			
      		//}
      	}
    	/*Borramos los campos de texto.*/
    	txtLetra.setText("");
	}
	
}
